// jwt: json web token
const jwt = require("jsonwebtoken");
const jwtSecretKey = "switch to a good private key",
  oneHour = 60 * 60 * 1000;

const sign = (payload) =>
    jwt.sign(payload, jwtSecretKey, {
      expiresIn: oneHour * 24 * 7,
    }),
  getPayloadByToken = (token) => {
    if (!token) return;
    try {
      return jwt.verify(token, jwtSecretKey);
    } catch {
      return;
    }
  };

module.exports = { sign, getPayloadByToken };
